﻿using EventBusDemo.Api.Domains.Orders.Events;
using EventBusDemo.EventBus.Abstractions.Local;

namespace EventBusDemo.Api.Domains.Orders.Services;

public class OrderService
{
    private readonly ILocalEventBus _localEventBus;

    public OrderService(ILocalEventBus localEventBus)
    {
        _localEventBus = localEventBus;
    }

    public async Task<Order> CreateOrder(string name)
    {
        var order = new Order()
        {
            Id = Guid.NewGuid(),
            Name = name,
        };

        await _localEventBus.Publish(new OrderCreatedDomainEvent()
        {
            Id = order.Id,
            Name = order.Name
        });

        return order;
    }
}
